package sitarflash;

import flash.display.Sprite;
import flash.Lib;
import oboe.controllers.Controller;
import oboe.controllers.ServerConnection;
import oboe.controllers.StateMachine;
import oboe.controllers.Translator;
import oboe.core.ISigSlot;
import oboe.core.Oboe;
import oboe.core.SigSlot;
import oboe.util.ISigSlotHelper;
import oboe.util.Prototype;

import sitarflash.states.home.Home;
import sitarflash.states.loading.Loading;
import sitarflash.states.login.Login;

using oboe.util.Prototype;
using oboe.util.ISigSlotHelper;


/**
 * ...
 * @author Felipe Manga
 */

class Main extends Sprite, implements ISigSlot
{
	private var sigslot:SigSlot;
	
	public function new() 
	{
		super();
		this.init( new StateMachine( new Controller(this) ) );
		
		this.message("addState", ["Loading", new Loading()]);
		this.message("addState", ["Login", new Login()]);
		this.message("addState", ["Home", new Home()]);
		
		this.sigslot.addChild( new ServerConnection("http://localhost/SitarPHP/bin/") );
		
		var translator = new Translator();
		translator.addMessage( "loginSuccess", this, "resetState",  ["Home"] );
		translator.addMessage( "onDoneLoading", this,  "setState", ["Login"] );
		
		this.sigslot.addChild( translator );
		
		this.message("setState", ["Loading"]);
	}
	
	@slot function loginSuccess():Void
	{
		this.message("resetState",
	}
	
	static function main() 
	{
		Oboe.initOboe(
			{
				
			},
			Main
		);
	}
	
}